package cn.openea.perpartner.mpwx.service.impl;

import cn.openea.perpartner.common.core.constant.UserConstants;
import cn.openea.perpartner.common.core.text.Convert;
import cn.openea.perpartner.common.core.utils.StringUtils;
import cn.openea.perpartner.mpwx.entity.MagmasConfig;
import cn.openea.perpartner.mpwx.mapper.MagmasConfigMapper;
import cn.openea.perpartner.mpwx.service.IMagmasConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (MsgmamgConfig)表服务实现类
 *
 * @author makejava
 * @since 2022-06-29 15:51:26
 */
@Service("magmasConfigService")
public class MagmasConfigServiceImpl implements IMagmasConfigService {
    @Autowired
    MagmasConfigMapper magmasConfigMapper;

    @Override
    public List<MagmasConfig> selectList() {
        return magmasConfigMapper.selectList(null);
    }

    @Override
    public MagmasConfig getById(Long id) {
        return magmasConfigMapper.selectById(id);
    }

    @Override
    public boolean save(MagmasConfig magmasConfig) {
        return magmasConfigMapper.insert(magmasConfig) > 0;
    }

    @Override
    public boolean updateById(MagmasConfig magmasConfig) {
        return magmasConfigMapper.updateById(magmasConfig) > 0;
    }


    @Override
    public String checkEventKeyUnique(MagmasConfig config) {
        Long configId = StringUtils.isNull(config.getUnid()) ? -1L : config.getUnid();
        MagmasConfig info = magmasConfigMapper.checkEventKeyUnique(config.getEventkey());
        if (StringUtils.isNotNull(info) && info.getUnid().longValue() != configId.longValue()) {
            return UserConstants.CONFIG_KEY_NOT_UNIQUE;
        }
        return UserConstants.CONFIG_KEY_UNIQUE;

    }

    @Override
    public void deleteConfigByIds(String ids) {
        Long[] configIds = Convert.toLongArray(ids);
        for (Long configId : configIds) {
            magmasConfigMapper.deleteById(configId);
        }
    }
}

